package tm;

import org.junit.jupiter.api.Test;
import java.util.List;

import static org.junit.jupiter.api.Assertions.assertEquals;

/**
 * @author haoly
 * @title TapeTest
 * @date 2025/4/23 11:27
 * @description 磁带测试类
 *
 * - 混合测试
 * - 测试磁带头向左移动
 * - 测试磁带头向右移动
 */
public class TapeTest {
    @Test
    public void testMixed(){
        char blankChar = '_';
        Tape tape = new Tape(List.of('1','0','1'), '1', List.of(), blankChar);
        System.out.println(tape);

        // 测试Tape类的基本操作
        assertEquals('1', tape.getMiddle());
        assertEquals(List.of('1','0','1'), tape.getLeft());
        assertEquals(List.of(), tape.getRight());
        assertEquals('_', tape.getBlank());

        // 测试Tape类的向左移动磁带头
        tape = tape.moveHeadLeft();
        System.out.println(tape);

        // 测试Tape类的写入
        tape = tape.write('0');
        System.out.println(tape);

        // 测试Tape类的向右移动磁带头
        tape = tape.moveHeadRight();
        System.out.println(tape);

        // 测试Tape类的向右移动磁带头
        tape = tape.moveHeadRight();
        System.out.println(tape);

        tape = tape.write('0');
        System.out.println(tape);
    }

    @Test
    public void testMoveHeadLeft(){
        char blankChar = '_';
        Tape tape = new Tape(List.of('1','0','1'), '1', List.of(), blankChar);

        // 101(1)
        System.out.println(tape);

        // 测试Tape类的向左移动磁带头 10(1)1
        tape = tape.moveHeadLeft();
        System.out.println(tape);

        // 测试Tape类的向左移动磁带头 1(0)11
        tape = tape.moveHeadLeft();
        System.out.println(tape);

        // 测试Tape类的向左移动磁带头 (1)011
        tape = tape.moveHeadLeft();
        System.out.println(tape);
        // 测试Tape类的向左移动磁带头 (_)1011
        tape = tape.moveHeadLeft();
        System.out.println(tape);

        // 测试Tape类的向左移动磁带头 (_)_1011
        tape = tape.moveHeadLeft();
        System.out.println(tape);
    }


    @Test
    public void testMoveHeadRight(){
        char blankChar = '_';
        Tape tape = new Tape(List.of('1','0'), '1', List.of('1'), blankChar);

        // 10(1)1
        System.out.println(tape);

        // 测试Tape类的向右移动磁带头 101(1)
        tape = tape.moveHeadRight();
        System.out.println(tape);

        // 测试Tape类的向右移动磁带头 1011(_)
        tape = tape.moveHeadRight();
        System.out.println(tape);

        // 测试Tape类的向右移动磁带头 1011_(_)
        tape = tape.moveHeadRight();
        System.out.println(tape);
    }
}
